#include "FastICANeuron.h"

CFastICANeuron::CFastICANeuron(int dimension, ACTIVE_FUNCTION_TYPE type) :
	m_W(dimension),
	m_ActiveFuncType(type)
{
	for (int i = 0; i < dimension; i++)
	{
		this->m_W[i] = ::rand() * 1.0 / RAND_MAX;
	}
	this->m_W = this->m_W / this->m_W.Norm();
}

double CFastICANeuron::Execute(const Vector2 & Input)
{
	double v = this->m_W.Dot(Input);

	if (this->m_ActiveFuncType == ACTIVE_FUNCTION_TYPE::TANH)
	{
		return ::tanh(v);
	}
	else if (this->m_ActiveFuncType == ACTIVE_FUNCTION_TYPE::EXP)
	{
		return v * ::exp(-0.5 * v * v);
	}
	else
	{
		return v;
	}
}

void CFastICANeuron::SetW(const Vector2 & wd)
{
	this->m_W = wd;
}

const Vector2 & CFastICANeuron::GetW()
{
	return this->m_W;
}

CFastICANeuron::ACTIVE_FUNCTION_TYPE CFastICANeuron::GetActiveType()
{
	return this->m_ActiveFuncType;
}